import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_1_25_0/testWidget/custom_input_cell.dart';

import '../testWidget/custom_input_cell.dart';
import '../testWidget/custom_input_cell.dart';

class TextUnderlinePage extends StatefulWidget {
  TextUnderlinePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _TextUnderlinePageState createState() => _TextUnderlinePageState();
}

class _TextUnderlinePageState extends State<TextUnderlinePage> {
  Color _getTextColor(BuildContext context) {
    Color color = Colors.redAccent;
    return color;
  }

  List<InlineSpan> _buildView(BuildContext context) {
    bool kIsWeb = false;
    List<InlineSpan> items = [];
    String defaultBlankData = '          ';
    String initText = 'gyqjla';
    items.add(TextSpan(
      text: defaultBlankData + 'hello',
      style: TextStyle(decorationColor: Colors.black, fontSize: flexible(context, 18.0)),
    ));
    items.add(initText.isNotEmpty
        ? WidgetSpan(
            child: Padding(
            padding: EdgeInsets.only(bottom: flexible(context, 2.0)),
            child: UnderLineText(
              textColor: _getTextColor(context),
              underLineColor: _getTextColor(context),
              text: initText,
            ),
          ))
        : TextSpan(
            text: defaultBlankData,
            style: TextStyle(decoration: TextDecoration.underline, decorationColor: Colors.black, fontSize: flexible(context, 18.0)),
          ));
    items.add(TextSpan(
      text: 'good',
      style: TextStyle(decorationColor: Colors.black, fontSize: flexible(context, 18.0)),
    ));
    return items;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Container(
          // color: Colors.green,
          width: flexible(context, 860.0),
          child: Column(
            children: [
              Stack(
                children: [
                  Container(
                    // color: Colors.redAccent,
                    width: flexible(context, 860.0),
                    height: flexible(context, 150),
                    padding: EdgeInsets.only(top: 20.0),
                    child: RichText(
                      text: TextSpan(children: _buildView(context)),
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(top: flexible(context, 10.0)),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

/// 带底部横线的文本（能够兼容web）
/// @owner weslywang
/// @groupInfo [ComponentGroupInfo.display]
class UnderLineText extends StatelessWidget {
  UnderLineText({this.text, this.fontSize = 18.0, this.textColor = Colors.black, this.underLineColor});

  final String text;
  final double fontSize;
  final Color textColor;
  final Color underLineColor;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(
        bottom: flexible(context, 2.0),
      ),
      decoration: BoxDecoration(
          border: Border(
              bottom: BorderSide(
        color: Colors.black,
        width: 1.0,
      ))),
      child: Text(
        text,
        style: TextStyle(
          fontSize: flexible(context, fontSize),
          color: textColor,
        ),
      ),
    );
  }
}
